<?php
  //=========================<script réaliser par :MOUMMID HAMZA>===================
include_once('connectBD.php');
include_once('beans/tacheBean.php');
include_once('configuration.php');

class tacheDao{



    public $listeTache= array();

   public function loadAllTache(){
     $req=connexion()->prepare("SELECT * from tache where idTache IN(select id_tache from tacheplannifiee union select idTache from intervention)");
     $req->execute();

     while($row = $req->fetch(PDO::FETCH_OBJ)) {
       $tache=new tacheBean();
       $tache->setIdTache($row->idTache);
       $tache->setObjectif(utf8_encode($row->objectif));
       $tache->setDesignation(utf8_encode($row->designation));
       $tache->setDateDebut(utf8_encode($row->dateDebut));

       $listeTache[]=$tache;
         }
       return $listeTache;
  }

function loadAllTacheByDesignation(){
       //fonction pour importer l'ensemble des cartes réseaux du table carte_reseau
         $requete_prepare_9=connexion()->prepare("SELECT * FROM tache where idTache in(select idTache from intervention union select id_tache from tacheplannifiee)"); // on prépare notre requête
         $requete_prepare_9->execute();
          while($row = $requete_prepare_9->fetch(PDO::FETCH_OBJ)) {
       $tache=new tacheBean();
       $tache->setIdTache($row->idTache);
       $tache->setObjectif(utf8_encode($row->objectif));

       $tache->setDesignation(utf8_encode($row->designation));
       $tache->setDateDebut(utf8_encode($row->dateDebut));

       $listeTache2[]=$tache;
         }
       return $listeTache2;//la fonction retourne un tableau de cartes réseaux choisis par le nomade
} 
  

  public function loadTache($designation,$datedebut){
     $req=connexion()->prepare("SELECT * from tache where designation like '$designation' and dateDebut like '$datedebut'");
     $req->execute();

     while($row = $req->fetch(PDO::FETCH_OBJ)) {
       $tache=new tacheBean();
       $tache->setIdTache($row->idTache);
       $tache->setObjectif(utf8_encode($row->objectif));
       $tache->setDesignation(utf8_encode($designation));
       $tache->setDateDebut(utf8_encode($datedebut));
         }
       return $tache;
  }

   public function insertTache($tache){
     $objectif=$tache->getObjectif();   $designation=$tache->getDesignation();   $dateDebut=$tache->getDateDebut();
     $req=connexion()->exec("INSERT into tache(objectif,designation,dateDebut) values('$objectif','$designation','$dateDebut')") or die('erreur insertion');
     $idtache=getLastInsertId();

     return $idtache;
   }


}

?>